﻿using System.IO;
using System.Security.Cryptography;


namespace ExperimentosConArchivos
{
    public static class Hashes
    {
        public static byte[] dameMD5(byte[] buff)
        {
            return dameHash(buff, MD5.Create());
        }

        public static byte[] dameMD5(Stream stream)
        {
            return dameHash(stream, MD5.Create());
        }

        public static byte[] dameSHA1(byte[] buff)
        {
            return dameHash(buff, SHA1.Create());
        }

        public static byte[] dameHash(byte[] buff, HashAlgorithm h)
        {
            return h.ComputeHash(buff);
        }

        public static byte[] dameHash(Stream stream, HashAlgorithm h)
        {
            return h.ComputeHash(stream);
        }

        public static string dameString16_MD5(byte[] buff)
        {
            return reprHexa(dameMD5(buff));
        }

        public static string dameString16_MD5(Stream stream)
        {
            return reprHexa(dameMD5(stream));
        }

        public static string dameString16_SHA1(byte[] buff)
        {
            return reprHexa(dameSHA1(buff));
        }

        public static string reprHexa(byte[] buff)
        {
            string ret = "";

            foreach (byte b in buff)
                ret += b.ToString("X2");

            return ret;
        }
    }
}
